package main.Q601_700;

public class Q661_670 {
    public static void main(String[] args) {
        System.out.println("Question661：图片平滑器");
        System.out.println("Question662：");
        System.out.println("Question663：");
        System.out.println("Question664：");
        System.out.println("Question665：");
        System.out.println("Question666：");
        System.out.println("Question667：");
        System.out.println("Question668：");
        System.out.println("Question669：");
        System.out.println("Question670：");
    }
}

class Question661{
    public int[] process(int[][] img,int i,int j){
        int[] result=new int[2];
        int row= img.length,col=img[0].length;
        result[0]+=img[i][j];//总和
        result[1]++;//个数
        if (i-1>=0){//上方
            result[0]+=img[i-1][j];
            result[1]++;
        }
        if (i+1<row){//下方
            result[0]+=img[i+1][j];
            result[1]++;
        }
        if (j-1>=0){//左方
            result[0]+=img[i][j-1];
            result[1]++;
        }
        if (j+1<col){//右方
            result[0]+=img[i][j+1];
            result[1]++;
        }
        if (i-1>=0&&j-1>=0){//左上
            result[0]+=img[i-1][j-1];
            result[1]++;
        }
        if (i-1>=0&&j+1<col){//右上
            result[0]+=img[i-1][j+1];
            result[1]++;
        }
        if (i+1<row&&j-1>=0){//左下
            result[0]+=img[i+1][j-1];
            result[1]++;
        }
        if (i+1<row&&j+1<col){//右下
            result[0]+=img[i+1][j+1];
            result[1]++;
        }
        return result;
    }
    public int[][] imageSmoother(int[][] img) {
        int row=img.length,col=img[0].length;
        int[][] result=new int[row][col];
        for (int i=0;i<row;i++){
            for (int j=0;j<col;j++){
                int[] temp=process(img,i,j);
                result[i][j]=temp[0]/temp[1];
            }
        }
        return result;
    }
}

class Question662{
    public int widthOfBinaryTree(TreeNode root) {
        return 1;
    }
}